package concurrentV;

public class AtomicAdder {
    private volatile int count = 0;

    private void add(){
        for (int i = 0; i < 100; i++) {
            synchronized (AtomicAdder.class){
                count++;
            }
        }
    }

    public static void main(String[] args) {
        AtomicAdder atomicAdder = new AtomicAdder();
        for (int i = 0; i < 100; i++) {
            new Thread(() -> atomicAdder.add()).start();
        }
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(atomicAdder.count);
    }
}
